

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流程表单数据字典</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/lib/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/lib/layuiadmin/style/admin.css" media="all">
    <style>
        html,body{height: 100%;}
        .layui-fluid{height: 95%;}
        .layui-row,.layui-col-xs12,.layui-card{height: 96%;}
    </style>

</head>
<body>


<div class="layui-fluid" id="LAY-component-grid-mobile">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-xs12" style="height: 10%;">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="" style="border-bottom:0;padding:0;">
                        <form class="layui-form" action="">
                            <table style="width:98%; table-layout:fixed;">
                                <tr>
                                    <td style='width:80px'>
                                        <a id="save" class="layui-btn layui-btn-sm st_back1"  onclick="save()" > 确  定</a>
                                    </td>
                                    <td></td>
                                    <td><input id='key' lay-filter="key" class="layui-input"/></td>
                                    <td><a class="layui-btn layui-btn-sm" onclick="search_data()"><i class="layui-icon">&#xe615;</i>查询</a></td>
                                </tr>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-header" style="height: 35px"><span id="title"></span></div>
                <div class="layui-card-body">
                    <table id="dataGrid" lay-filter="dataGrid"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/static/lib/layuiadmin/layui/layui.js"></script>
<script src="../../../common/common.js"></script>
<script src="../../../common/jquery-3.3.1.min.js"></script>
<script src="../../../common/listTree.js"></script>
<script src="../../../common/dataGrid.js"></script>
<script>
    var index = parent.layer.getFrameIndex(window.name);
    var iframe = RequestURLParam.getParam("iframeId");
    var type = RequestURLParam.getParam("type");
    var fid = RequestURLParam.getParam("fid");
    var form, laydate, table;
    var grid;
    $(document).ready(function () {
        layui.use(['form', 'laydate', 'table'], function () {
            form = layui.form;
            laydate = layui.laydate;
            table = layui.table;
            if(type=="customer"){
                $("#title").html("客户列表");
                loadCustomer();
            }else if(type=="contract"){
                $("#title").html("合同列表");
                loadContract();
            }else if(type=="product"){
                $("#title").html("产品列表");
                loadProduct();
            }
        });
    });

    function loadCustomer() {
        table.render({
            elem: '#dataGrid'
            ,id:'dataGrid'
            ,height: 'full-185'
            ,url: '/erp-customer-info/select/page' //数据接口
            ,page: true //开启分页
            ,method: 'post'
            ,limit:10
            ,limits:[10,20,50,100]
            ,response: {
                statusCode: 200 //规定成功的状态码，默认：0
                ,countName: 'total' //规定数据总数的字段名称，默认：count
                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
            }
            ,cols: [[ //表头
                {type:'radio'}
                ,{field: 'id', title: 'ID', width:40}
                ,{field: 'clientNameCn', title: '客户名称', width:'50%'}
                ,{field: 'clientCode', title: '客户编号', width:'38.2%'}
            ]]
        });

        table.on('row(dataGrid)', function(obj){
            rootClick(obj.data);
        });
    }

    function loadContract() {
        table.render({
            elem: '#dataGrid'
            ,id:'dataGrid'
            ,height: 'full-185'
            ,url: '/erpContract/selectPageList' //数据接口
            ,where:{"ecCustomer": fid}
            ,page: true //开启分页
            ,method: 'post'
            ,limit:10
            ,limits:[10,20,50,100]
            ,response: {
                statusCode: 200 //规定成功的状态码，默认：0
                ,countName: 'total' //规定数据总数的字段名称，默认：count
                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
            }
            ,cols: [[ //表头
                {type:'radio'}
                ,{field: 'id', title: 'ID', width:40}
                ,{field: 'ecName', title: '合同名称', width:'50%'}
                ,{field: 'ecNumber', title: '合同编号', width:'38.2%'}
            ]]
        });

        table.on('row(dataGrid)', function(obj){
            rootClick(obj.data);
        });
    }

    function loadProduct() {
        table.render({
            elem: '#dataGrid'
            ,id:'dataGrid'
            ,height: 'full-185'
            ,url: '/erpProduct/select/page/byid' //数据接口
            ,page: true //开启分页
            ,method: 'post'
            ,limit:10
            ,limits:[10,20,50,100]
            ,response: {
                statusCode: 200 //规定成功的状态码，默认：0
                ,countName: 'total' //规定数据总数的字段名称，默认：count
                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
            }
            ,cols: [[ //表头
                {type:'radio'}
                ,{field: 'id', title: 'ID', width:40}
                ,{field: 'proName', title: '产品名称', width:'50%'}
                ,{field: 'proCoding', title: '产品编号', width:'38.2%'}
            ]]
        });

        table.on('row(dataGrid)', function(obj){
            rootClick(obj.data);
        });
    }

    function rootClick(e) {
        var document = $('#'+iframe, parent.document)[0];
        node = $('#'+iframe,parent.document)[0].contentWindow.node;
        if(type=="customer"){
            node.attr("value", e.clientNameCn);
            node.attr("value-code",  e.id);
            node.attr("value-json", JSON.stringify(e).replace(/\"/g,'\''));
        }else if(type=="contract"){
            node.attr("value", e.ecName);
            node.attr("value-code",  e.id);
            node.attr("value-json", JSON.stringify(e).replace(/\"/g,'\''));
        }else if(type=="product"){
            node.attr("value", e.proName);
            node.attr("value-code",  e.id);
            node.attr("value-json", JSON.stringify(e).replace(/\"/g,'\''));
        }
        parent.layer.close(index);
    }

    //保存
    function save() {
        var data = table.checkStatus('dataGrid').data;

        node = $('#'+iframe, parent.document)[0].contentWindow.node;
        if(type=="customer"){
            node.attr("value", data[0].clientNameCn);
            node.attr("value-code",  data[0].id);
            node.attr("value-json", JSON.stringify(data[0]).replace(/\"/g,'\''));
        }else if(type=="contract"){
            node.attr("value", data[0].ecName);
            node.attr("value-code",  data[0].id);
            node.attr("value-json", JSON.stringify(data[0]).replace(/\"/g,'\''));
        }else if(type=="product"){
            node.attr("value", data[0].proName);
            node.attr("value-code",  data[0].id);
            node.attr("value-json", JSON.stringify(data[0]).replace(/\"/g,'\''));
        }

        parent.layer.close(index);
    }


    //客户条件查询
    function search_data() {
        var key = $('#key').val();
        if(type=="customer"){
            table.reload('dataGrid', {
                where:{
                    "clientNameCn": key
                }
            });
        }else if(type=="contract"){
            table.reload('dataGrid', {
                where:{
                    'key': key
                }
            });
        }else if(type=="product"){
            table.reload('dataGrid', {
                where:{
                    'proName': key
                }
            });
        }

    }
</script>
</body>
</html>